// 一艘船最多只能装30公斤的古董，问装哪些古董价值最大？

// weight是重量，value是价值
let _arr = [
  { name: '1号古董', weight: 4, value: 2 },
  { name: '2号古董', weight: 3, value: 5 },
  { name: '3号古董', weight: 2, value: 1 },
  { name: '4号古董', weight: 7, value: 5 },
  { name: '5号古董', weight: 8, value: 10 },
  { name: '6号古董', weight: 4, value: 6 },
  { name: '7号古董', weight: 2, value: 5 },
  { name: '8号古董', weight: 3, value: 9 },
  { name: '9号古董', weight: 10, value: 8 },
  { name: '10号古董', weight: 6, value: 4 },
  { name: '11号古董', weight: 4, value: 5 },
]

var NewArr = [], temp, sum = 0
for (let i = 0; i < _arr.length; i++) {
  for (let j = 0; j < _arr.length; j++) {
    if (_arr[i].value > _arr[j].value) {
      temp = _arr[i]
      _arr[i] = _arr[j]
      _arr[j] = temp
    }
  }
}

for (let z = 0; z < _arr.length; z++) {
  sum += _arr[z].weight
  if (sum > 30) {
    break
  }
  NewArr.push(_arr[z])
}
// console.log(_arr)

console.log(NewArr)